/****************************************************************
 *This file is main.c
 ****************************************************************/

#include "include.h"

/****************************************************************
 *This function is main process,
 *	(1)first init system source
 *	(2)create five thread
 *	(3)obstruct main process,and let five thread to run
 ****************************************************************/
int main(void)
{
	//inner variable
	//pthread_t pth1, pth2, pth3, pth4, pth5, pth11, pth21, pth22, pth23, pth24;
	pthread_t pth1, pth4, pth5, pth11, pth21, pth22, pth23, pth24;
	int ret;
	struct sched_param param4;
	pthread_attr_t attr4;

	//none meaning,avoid compile warning
	ret = 0;
	ret = ret;

	//***********system init********************//
	system_init();

	//set signal process function
	signal(SIGPIPE, sig_pro_func);

	//config pthread_four sched method and prioriy
	param4.sched_priority = 99;
	pthread_attr_init(&attr4);
	pthread_attr_setschedpolicy(&attr4, SCHED_FIFO);
	pthread_attr_setschedparam(&attr4, &param4);
	pthread_attr_setinheritsched(&attr4,PTHREAD_EXPLICIT_SCHED);

	//give system running notice
	fprintf(stderr,"If no warning notice,system_init ok! \n");
	fprintf(stderr,"I will run PXI5012 server!	:) \n");

	//***********create    thread****************//
	//creat thread1
	ret = pthread_create(&pth1, NULL, thread1, NULL);

	//creat thread2
	//ret = pthread_create(&pth2, NULL, thread2, NULL);

	//creat thread3
	//ret = pthread_create(&pth3, NULL, thread3, NULL);

	//creat thread4
	ret = pthread_create(&pth4, &attr4, thread4, NULL);

	//creat thread5
	ret = pthread_create(&pth5, NULL, thread5, NULL);

	//creat thread11
	ret = pthread_create(&pth11, NULL, thread11, NULL);

	//creat thread21
	ret = pthread_create(&pth21, NULL, thread21, NULL);

	//creat thread22
	ret = pthread_create(&pth22, NULL, thread22, NULL);

	//creat thread23
	ret = pthread_create(&pth23, NULL, thread23, NULL);

	//creat thread24
	ret = pthread_create(&pth24, NULL, thread24, NULL);

	//************let	thread	 to   run************//
	//let thread  to run
	pthread_join(pth1, NULL);
	//pthread_join(pth2, NULL);
	//pthread_join(pth3, NULL);
	pthread_join(pth4, NULL);
	pthread_join(pth5, NULL);
	pthread_join(pth11, NULL);
	pthread_join(pth21, NULL);
	pthread_join(pth22, NULL);
	pthread_join(pth23, NULL);
	pthread_join(pth24, NULL);

	//not run to this, so we should reboot system
	fprintf(stderr,"master module thread was exit!\n");
	system("touch reboot");
	system("reboot");

	return 0;
}

#ifdef	TST_CODE_SWITCH
	//fprintf(stderr,"judgement_exist_time is :%x\n",judgement_exist_time);
#endif

